home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / StaticTView.h < prev    next >
C/C++ Source or Header  |  1992-08-21  |  7KB  |  251 lines

  1. #ifndef StaticTView_First
  2. #ifdef __GNUG__
  3. //pragma once
  4. #pragma interface
  5. #endif
  6. #define StaticTView_First
  7.   
  8. #include "Text.h"
  9. #include "Mark.h"
  10. #include "ObjArray.h"
  11. #include "View.h"
  12.  
  13. class TextFormatter;
  14. class TextPainter;
  15.  
  16. enum TViewAlign {                               // alignment of the view 
  17.     eTViewLeft, 
  18.     eTViewRight, 
  19.     eTViewCenter  
  20. };
  21.  
  22. enum TextViewFlags {
  23.     eTextViewNone       =   0,
  24.     eTextViewReadOnly   =   BIT(eViewLast+1),   // disable text modifications
  25.     eTextViewInvis      =   BIT(eViewLast+2),   // show invisible characters
  26.     eTextWantFindFocus  =   BIT(eViewLast+3),   // text view wants find focus
  27.     eTextViewNoBatch    =   BIT(eViewLast+4),   // do not batch characters
  28.     eTextViewModified   =   BIT(eViewLast+5),   // view size modified
  29.     eTextViewDragAndDrop=   BIT(eViewLast+6),   // enable drag&drop
  30.     eTextViewNoClip     =   BIT(eViewLast+7),   // clip at inner rectangle
  31.     eTextViewLast       =   eViewLast+6,     
  32.     eTextViewDefault    =   eVObjEnabled
  33. };
  34.  
  35. extern Rectangle gFitRect;
  36.  
  37. const bool cWordWrap= TRUE,
  38.        cNoWordWrap= !cWordWrap,
  39.        
  40.        cShowInvisibles= TRUE,
  41.        cHideInvisibles= !cShowInvisibles,
  42.        
  43.        cRevealTop= TRUE,
  44.        cDoNotRevealTop= FALSE;
  45.            
  46. const int cSizeVariable= -1,
  47.       cFit= cSizeVariable;
  48.  
  49. //---- StaticTextView -------------------------------------------------------
  50.  
  51. class StaticTextView: public View {
  52. public:
  53.     MetaDef(StaticTextView);
  54.     
  55.     StaticTextView(
  56.     EvtHandler *eh, Rectangle r, Text *t, 
  57.     bool wrap= cWordWrap,
  58.     TextViewFlags= eTextViewDefault, 
  59.     Point border= gBorder, 
  60.     TViewAlign m= eTViewLeft,
  61.     int id= cIdNone
  62.     );  // if contentRect.extent.y is set to cSizeVariable 
  63.     // extent.y is adapted to extent of largest text line
  64.     
  65.     ~StaticTextView();
  66.     
  67.     //---- rendering
  68.     void PrintAdorn(Rectangle, int gPageNo);
  69.     void Draw(Rectangle);
  70.     
  71.     //---- composing
  72.     virtual void Repair(int from, int to, bool redraw);
  73.     virtual void RepairAll();    // reformat and redisplay whole text
  74.     
  75.     virtual void InvalidateRange(int from, int to);
  76.     virtual void InvalidateRange(int from, Point fp, int to, Point tp);
  77.  
  78.     virtual Text *SetText(Text*, bool scroll= cRevealTop);     // returns old text
  79.     void SetFormatter(TextFormatter *f);       
  80.     void SetPainter(TextPainter *tp); 
  81.     void SetPager(TextPager *tp);
  82.       
  83.     virtual void SetString(byte *str, int len= -1);
  84.     
  85.     Text *GetText();
  86.     
  87.     //---- acessing
  88.     virtual void SetFont(Font *fd);
  89.     TViewAlign GetAlignment() 
  90.     { return align; }
  91.     void SetAlign(TViewAlign);
  92.     void ShowInvisibles(bool);
  93.     bool GetShowInvis();
  94.     void SetNoBatch(bool);
  95.     bool GetNoBatch();
  96.     void SetWordWrap(bool m);
  97.     bool GetWordWrap();
  98.     bool Empty();
  99.     int Lines();
  100.     int NumberOfLines();
  101.  
  102.     //---- mapping
  103.     virtual void PointToPoint(
  104.     Point p, Point *viewPos, int *lineNo, int *CharNo, bool relative= TRUE
  105.     ); 
  106.     virtual int CharToPoint(
  107.     int charNo, int *lineNo, 
  108.     Point *viewPos, bool relative= TRUE
  109.     );
  110.     virtual Point LineToPoint(
  111.     int line, bool basePoint= FALSE, 
  112.     bool relative= TRUE
  113.     );
  114.     virtual int PointToLine(Point p);
  115.     virtual int CharToLine(int ch);   // return line number of character
  116.     Rectangle NextPageBreak(int pageno, Rectangle r);
  117.  
  118.     //---- line structure access
  119.     LineMark *MarkAtLine(int i);
  120.     int StartLine(int l);
  121.     int EndLine(int l);
  122.     int LineHeight(int l);
  123.     int BaseHeight(int l);
  124.     
  125.     //---- size managment
  126.     // adapt view size to the extension of text if wrap is set to TRUE only 
  127.     // the height is changed
  128.     void SetExtent(Point p); // (reformats text)
  129.     Metric GetMinSize();
  130.     Point GetInnerOrigin();
  131.     Point GetInnerExtent();
  132.     void SetBorder(Point newBorder);
  133.     Point GetBorder();
  134.  
  135.     //----- client marks    
  136.     void AddMark(Mark *);
  137.     Mark *RemoveMark(Mark *);
  138.     Iterator *GetMarkIter(); 
  139.     MarkList *GetMarkList();    
  140.  
  141.     //----- debugging
  142.     void InspectorId(char *buf, int sz);
  143.     void CollectParts(Collection*);
  144.  
  145.     //----- generic methods
  146.     char *AsString();
  147.     OStream& PrintOn(OStream&);
  148.     IStream& ReadFrom(IStream&);
  149.     void Dump();
  150.     void ClassInvariant();
  151.     
  152.     //---- static methods
  153.     static Metric MeasureText(char *txt, Font* fd, int minwidth, int nlines= 1);
  154.     static void DrawBoxedText(Rectangle r, char *txt, Font*, Ink *ink, bool wrap);
  155.     
  156. protected:
  157.     Text *text;                 // shown text
  158.     class TextFormatter *formatter; // formatter
  159.     class TextPainter *painter; // text painter/mapper
  160.     class TextPager *pager;     // break view into pages
  161.     TViewAlign align;           // view alignment
  162.     bool wrap;                  // break line at view boundary
  163.     bool drawViewBorder;        
  164.     bool horExtend;  
  165.     Point border;               // border around the text
  166.  
  167.     int nLines;                 // number of lines
  168.     ObjArray *lines;            // array of line marks, grows dynamically
  169.     MarkList *marks;
  170.     
  171.     int cline;                  // line and position map cache
  172.     int cYPosition;
  173.     
  174.     //---- 
  175.     void Init(
  176.     Rectangle, Text*, bool wrap, TextViewFlags, Point, TViewAlign
  177.     );
  178.     int UpdateView(
  179.     int from, int to, int n, ObjArray *newLines, bool redraw
  180.     );
  181.     void UpdateComposition(int from, int to, int n, ObjArray *newLines);
  182.     void UpdateExtent(int dy);     
  183.     void InvalidateDiff(Point newExtent, Point newOrigin);
  184.     int AlignView(int nexExtent);
  185.     void SwapRange(int &a, int &b);
  186.  
  187.     virtual void DrawLine(
  188.     Point p,int line,Rectangle lineRect, 
  189.     Rectangle clip
  190.     );
  191. };
  192.  
  193. //---- inlines
  194.  
  195. inline int StaticTextView::Lines()
  196. {
  197.     return nLines;
  198. }
  199.  
  200. inline int StaticTextView::NumberOfLines()
  201. {
  202.     return Lines();
  203. }
  204.  
  205. inline Text *StaticTextView::GetText()
  206.     return text; 
  207. }
  208.     
  209. inline bool StaticTextView::Empty()
  210.     return text->Size() == 0; 
  211. }
  212.  
  213. inline LineMark *StaticTextView::MarkAtLine(int i)
  214.     return (LineMark*)(*lines)[i]; 
  215. }
  216.  
  217. inline int StaticTextView::StartLine(int l)
  218.     return MarkAtLine(l)->pos; 
  219. }
  220.  
  221. inline int StaticTextView::EndLine(int l)
  222.     return MarkAtLine(l)->pos + MarkAtLine(l)->len; 
  223. }
  224.  
  225. inline Point StaticTextView::GetInnerOrigin()  
  226.     return contentRect.origin+border; 
  227. }
  228.     
  229. inline Point StaticTextView::GetInnerExtent()  
  230.     return contentRect.extent-2*border; 
  231. }
  232.  
  233. inline void StaticTextView::SetBorder(Point newBorder)
  234.     border= newBorder; 
  235. }
  236.  
  237. inline Point StaticTextView::GetBorder()
  238.     return border; 
  239. }
  240.  
  241. #endif     
  242.